package com.yanqu.road.server.cmd.newmonopolymkt.res;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.newmonopolymkt.NewMonopolyMarketModule;
import com.yanqu.road.server.manger.systemgroup.newmonopolymarket.NewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = NewMonopolyMarketProto.NewMonopolyMarketResGrabActionReqMsg.class, respMsg = NewMonopolyMarketProto.NewMonopolyMarketResGrabActionRespMsg.class)
@Cmd(code = GameProtocol.S_NEW_MONOPOLY_MARKET_CHANGE_TEAM_CONFIRM, desc = "修改队伍")
public class NewMonopolyMarketResGrabChangeTeamConfirmCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(!NewMonopolyMarketMgr.canEnterSystem(player)){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        NewMonopolyMarketProto.NewMonopolyMarketResGrabChangeTeamConfirmReqMsg req = NewMonopolyMarketProto.NewMonopolyMarketResGrabChangeTeamConfirmReqMsg.parseFrom(packet.getBytes());
        ret = player.getModule(NewMonopolyMarketModule.class).changeTeam(req.getAction(), req.getResGroupId(), req.getPosIndex());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_NEW_MONOPOLY_MARKET_CHANGE_TEAM_CONFIRM, NewMonopolyMarketProto.NewMonopolyMarketResGrabChangeTeamConfirmRespMsg.newBuilder().setRet(ret));
        }
    }
}
